{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Configuring pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# import numpy and pandas\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# used for dates\n",
    "import datetime\n",
    "from datetime import datetime, date\n",
    "\n",
    "# Set some pandas options controlling output format\n",
    "pd.set_option('display.notebook_repr_html', False)\n",
    "pd.set_option('display.max_columns', 8)\n",
    "pd.set_option('display.max_rows', 10)\n",
    "pd.set_option('display.width', 80)\n",
    "\n",
    "# bring in matplotlib for graphics\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating a DataFrame using NumPy function results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   0\n",
       "0  1\n",
       "1  2\n",
       "2  3\n",
       "3  4\n",
       "4  5"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# From a 1-d array\n",
    "pd.DataFrame(np.arange(1, 6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "    0   1\n",
       "0  10  11\n",
       "1  20  21"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a DataFrame from a 2-d ndarray\n",
    "df = pd.DataFrame(np.array([[10, 11], [20, 21]]))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=2, step=1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# retrieve the columns index\n",
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  Philadelphia\n",
       "0        70            71\n",
       "1        90            91"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# specify column names\n",
    "df = pd.DataFrame(np.array([[70, 71], [90, 91]]),\n",
    "                  columns=['Missoula', 'Philadelphia'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many rows?\n",
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what is the dimensionality\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating a DataFrame using a Python dictionary and pandas Series objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  Philadelphia\n",
       "0        70            90\n",
       "1        71            91"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# initialization using a python dictionary\n",
    "temps_missoula = [70, 71]\n",
    "temps_philly = [90, 91]\n",
    "temperatures = {'Missoula': temps_missoula,\n",
    "                'Philadelphia': temps_philly}\n",
    "pd.DataFrame(temperatures)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "    0   1\n",
       "0  70  90\n",
       "1  71  91"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create a DataFrame for a list of Series objects\n",
    "temps_at_time0 = pd.Series([70, 90])\n",
    "temps_at_time1 = pd.Series([71, 91])\n",
    "df = pd.DataFrame([temps_at_time0, temps_at_time1])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  Philadelphia\n",
       "0       NaN           NaN\n",
       "1       NaN           NaN"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# try to specify column names\n",
    "df = pd.DataFrame([temps_at_time0, temps_at_time1],\n",
    "                  columns=['Missoula', 'Philadelphia'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  Philadelphia\n",
       "0        70            90\n",
       "1        71            91"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# specify names of columns after creation\n",
    "df = pd.DataFrame([temps_at_time0, temps_at_time1])\n",
    "df.columns = ['Missoula', 'Philadelphia']\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  Philadelphia\n",
       "0        70            90\n",
       "1        71            91"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# construct using a dict of Series objects\n",
    "temps_mso_series = pd.Series(temps_missoula)\n",
    "temps_phl_series = pd.Series(temps_philly)\n",
    "df = pd.DataFrame({'Missoula': temps_mso_series,\n",
    "                   'Philadelphia': temps_phl_series})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Missoula  New York  Philadelphia\n",
       "0      70.0       NaN          90.0\n",
       "1      71.0      85.0          91.0\n",
       "2       NaN      87.0           NaN"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# alignment occurs during creation\n",
    "temps_nyc_series = pd.Series([85, 87], index=[1, 2])\n",
    "df = pd.DataFrame({'Missoula': temps_mso_series,\n",
    "                   'Philadelphia': temps_phl_series,\n",
    "                   'New York': temps_nyc_series})\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating a DataFrame from a CSV file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# read in the data and print the first five rows\n",
    "# use the Symbol column as the index, and \n",
    "# only read in columns in positions 0, 2, 3, 7\n",
    "sp500 = pd.read_csv(\"data/sp500.csv\", \n",
    "                    index_col='Symbol', \n",
    "                    usecols=[0, 2, 3, 7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                        Sector   Price  Book Value\n",
       "Symbol                                            \n",
       "MMM                Industrials  141.14      26.668\n",
       "ABT                Health Care   39.60      15.573\n",
       "ABBV               Health Care   53.95       2.954\n",
       "ACN     Information Technology   79.79       8.326\n",
       "ACE                 Financials  102.91      86.897"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# peek at the first 5 rows of the data using .head()\n",
    "sp500.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "500"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many rows of data?  Should be 500\n",
    "len(sp500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(500, 3)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what is the shape?\n",
    "sp500.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1500"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what is the size?\n",
    "sp500.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['MMM', 'ABT', 'ABBV', 'ACN', 'ACE', 'ACT', 'ADBE', 'AES', 'AET', 'AFL',\n",
       "       ...\n",
       "       'XEL', 'XRX', 'XLNX', 'XL', 'XYL', 'YHOO', 'YUM', 'ZMH', 'ZION', 'ZTS'],\n",
       "      dtype='object', name='Symbol', length=500)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# examine the index\n",
    "sp500.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Sector', 'Price', 'Book Value'], dtype='object')"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get the columns\n",
    "sp500.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting columns of a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Symbol\n",
       "MMM                Industrials\n",
       "ABT                Health Care\n",
       "ABBV               Health Care\n",
       "ACN     Information Technology\n",
       "ACE                 Financials\n",
       "Name: Sector, dtype: object"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# retrieve the Sector column\n",
    "sp500['Sector'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(sp500['Sector'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "         Price  Book Value\n",
       "Symbol                    \n",
       "MMM     141.14      26.668\n",
       "ABT      39.60      15.573\n",
       "ABBV     53.95       2.954\n",
       "ACN      79.79       8.326\n",
       "ACE     102.91      86.897"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# retrieve the Price and Book Value columns\n",
    "sp500[['Price', 'Book Value']].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show that this is a DataFrame\n",
    "type(sp500[['Price', 'Book Value']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Symbol\n",
       "MMM     141.14\n",
       "ABT      39.60\n",
       "ABBV     53.95\n",
       "ACN      79.79\n",
       "ACE     102.91\n",
       "         ...  \n",
       "YHOO     35.02\n",
       "YUM      74.77\n",
       "ZMH     101.84\n",
       "ZION     28.43\n",
       "ZTS      30.53\n",
       "Name: Price, Length: 500, dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# attribute access of column by name\n",
    "sp500.Price"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting rows of a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector        Industrials\n",
       "Price              141.14\n",
       "Book Value         26.668\n",
       "Name: MMM, dtype: object"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get row with label MMM\n",
    "# returned as a Series\n",
    "sp500.loc['MMM']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                        Sector   Price  Book Value\n",
       "Symbol                                            \n",
       "MMM                Industrials  141.14      26.668\n",
       "MSFT    Information Technology   40.12      10.584"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rows with label MMM and MSFT\n",
    "# this is a DataFrame result\n",
    "sp500.loc[['MMM', 'MSFT']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             Sector   Price  Book Value\n",
       "Symbol                                 \n",
       "MMM     Industrials  141.14      26.668\n",
       "ABBV    Health Care   53.95       2.954"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get rows in location 0 and 2\n",
    "sp500.iloc[[0, 2]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 10)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get the location of MMM and A in the index\n",
    "i1 = sp500.index.get_loc('MMM')\n",
    "i2 = sp500.index.get_loc('A')\n",
    "(i1, i2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             Sector   Price  Book Value\n",
       "Symbol                                 \n",
       "MMM     Industrials  141.14      26.668\n",
       "A       Health Care   56.18      16.928"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# and get the rows\n",
    "sp500.iloc[[i1, i2]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scalar lookup by label or location using .at[] and .iat[] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "141.13999999999999"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# by label in both the index and column\n",
    "sp500.at['MMM', 'Price']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "141.13999999999999"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# by location.  Row 0, column 1\n",
    "sp500.iat[0, 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Slicing using the [] operator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                        Sector   Price  Book Value\n",
       "Symbol                                            \n",
       "MMM                Industrials  141.14      26.668\n",
       "ABT                Health Care   39.60      15.573\n",
       "ABBV               Health Care   53.95       2.954\n",
       "ACN     Information Technology   79.79       8.326\n",
       "ACE                 Financials  102.91      86.897"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# first five rows\n",
    "sp500[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                        Sector  Price  Book Value\n",
       "Symbol                                           \n",
       "ABT                Health Care  39.60      15.573\n",
       "ABBV               Health Care  53.95       2.954\n",
       "ACN     Information Technology  79.79       8.326"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ABT through ACN labels\n",
    "sp500['ABT':'ACN']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting rows using Boolean selection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Symbol\n",
       "MMM     False\n",
       "ABT      True\n",
       "ABBV     True\n",
       "ACN      True\n",
       "ACE     False\n",
       "        ...  \n",
       "YHOO     True\n",
       "YUM      True\n",
       "ZMH     False\n",
       "ZION     True\n",
       "ZTS      True\n",
       "Name: Price, Length: 500, dtype: bool"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what rows have a price < 100?\n",
    "sp500.Price < 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                        Sector  Price  Book Value\n",
       "Symbol                                           \n",
       "ABT                Health Care  39.60      15.573\n",
       "ABBV               Health Care  53.95       2.954\n",
       "ACN     Information Technology  79.79       8.326\n",
       "ADBE    Information Technology  64.30      13.262\n",
       "AES                  Utilities  13.61       5.781\n",
       "...                        ...    ...         ...\n",
       "XYL                Industrials  38.42      12.127\n",
       "YHOO    Information Technology  35.02      12.768\n",
       "YUM     Consumer Discretionary  74.77       5.147\n",
       "ZION                Financials  28.43      30.191\n",
       "ZTS                Health Care  30.53       2.150\n",
       "\n",
       "[407 rows x 3 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now get the rows with Price < 100\n",
    "sp500[sp500.Price < 100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Symbol\n",
       "HCBK    9.80\n",
       "HBAN    9.10\n",
       "SLM     8.82\n",
       "WIN     9.38\n",
       "Name: Price, dtype: float64"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get only the Price where Price is < 10 and > 0\n",
    "r = sp500[(sp500.Price < 10) & \n",
    "          (sp500.Price > 6)] ['Price']\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "         Price       Sector\n",
       "Symbol                     \n",
       "ACT     213.77  Health Care\n",
       "ALXN    162.30  Health Care\n",
       "AGN     166.92  Health Care\n",
       "AMGN    114.33  Health Care\n",
       "BCR     146.62  Health Care\n",
       "...        ...          ...\n",
       "REGN    297.77  Health Care\n",
       "TMO     115.74  Health Care\n",
       "WAT     100.54  Health Care\n",
       "WLP     108.82  Health Care\n",
       "ZMH     101.84  Health Care\n",
       "\n",
       "[19 rows x 2 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# price > 100 and in the Health Care Sector\n",
    "r = sp500[(sp500.Sector == 'Health Care') & \n",
    "          (sp500.Price > 100.00)] [['Price', 'Sector']]\n",
    "r"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting across both rows and columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             Sector  Price\n",
       "Symbol                    \n",
       "ABT     Health Care  39.60\n",
       "ZTS     Health Care  30.53"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select the price and sector columns for ABT and ZTS\n",
    "sp500.loc[['ABT', 'ZTS']][['Sector', 'Price']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
